package com.kuizii.server.naming;

import java.io.File;
import java.io.FileReader;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class DefaultClusterServer implements ClusterServer {


    List<String> nodes;


    public DefaultClusterServer() {
        File file = new File(System.getProperty("user.dir") + "/conf/clusterList");
        FileReader fileReader = null;
        try {
            fileReader = new FileReader(file);
            char[] chars = new char[(int) file.length()];
            int read = fileReader.read(chars, 0, (int) file.length());
            String s = new String(chars);
            if (s == null || s.length() == 0) {
                nodes.add("127.0.0.1");
            } else {
                Arrays.asList(s.split("\r\n")).forEach(x -> {
                    if (x == null || x.isEmpty()) {
                        return;
                    } else {
                        nodes.add(x);
                    }
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public DefaultClusterServer(List<String> node) {
        this.nodes = node;
    }


    @Override
    public Map<String, Cluster> getNameNodes() {
        return null;
    }
}
